home *** CD-ROM | disk | FTP | other *** search
/ CICA 1995 September (Japanese) / CICA Shareware for Windows CD-ROM (Walnut Creek) (September 1995) (Japanese) (Disc 2).iso / disc2 / patches / symantec / mfcsm2.exe / SIMNEW.EXE / MFC / SAMPLES / DOCTEMP / DOCTEMP.WMC < prev    next >
Encoding:
Text File  |  1993-10-06  |  14.2 KB  |  533 lines

  1. // Filename: DOCTEMP.WMC                                    
  2. // "DOCTEMP" Generated by Visual Programmer.                
  3. // Author:   Blue Sky                                       
  4.  
  5. // 
  6. // ***********************************************************************
  7. // Do not add code here. Add code in the .CPP file.
  8. // 
  9. // This file is maintained by the Switch-It Module.
  10. // As you make changes in your applications design,
  11. // this file is automatically updated, therefore you never modify this file.
  12. // 
  13. // 
  14. // 
  15. // For more information,
  16. // see the section "How code is generated" in the documentation.
  17. // 
  18. // ***********************************************************************
  19. // 
  20.  
  21. // *************************************************************
  22. //                GLOBAL VARIABLES
  23. // *************************************************************
  24.  
  25. BOOL      bHelpSupport   = FALSE; // Controlling Help Support
  26. DWORD     dwDialogProp   = 0; // Controlling Dialog Box Color
  27. BOOL      b256Color      = TRUE;  // Controlling bitmap drawing
  28. BOOL      bPreCreateCheck= TRUE;  // Controlling PreCreateWindow handling
  29. HINSTANCE hBMPInst       = 0;     // Handle to instance for bitmaps
  30. UINT      wPrivateMessage= RegisterWindowMessage("BLDPrivateMessage");
  31.  
  32.  
  33.  
  34.  
  35.  
  36. // *************************************************************
  37. // Member Functions for Class: Cwm_BaseApplication
  38. // Base Class                : CWinApp
  39. // *************************************************************
  40.  
  41.  
  42. BEGIN_MESSAGE_MAP(Cwm_BaseApplication, CWinApp)
  43.     
  44.     //  Processing of linked menu items in menu: SIMPLE  
  45.     
  46. ON_COMMAND(IDM_NewWindow, wmIDM_NewWindowCM)
  47. ON_COMMAND(IDM_Cascade, wmIDM_CascadeCM)
  48. ON_COMMAND(IDM_Tile, wmIDM_TileCM)
  49. ON_COMMAND(IDM_ArrangeIcons, wmIDM_ArrangeIconsCM)
  50. ON_COMMAND(IDM_CloseActive, wmIDM_CloseActiveCM)
  51. END_MESSAGE_MAP()
  52.  
  53.  
  54. Cwm_BaseApplication::Cwm_BaseApplication (const char* pName)
  55.     : CWinApp (pName)
  56. {
  57.     pWndClient = NULL;
  58. }
  59.  
  60.  
  61. BOOL Cwm_BaseApplication::InitApplication()
  62. {
  63.  
  64.     return CWinApp::InitApplication();
  65. }
  66.  
  67.  
  68.  
  69. BOOL Cwm_BaseApplication::InitInstance()
  70. {
  71.     OFSTRUCT of;
  72.     int      len;
  73.     char     *pStr;
  74.  
  75.     if(dwDialogProp&BLDGRAY_DIALOGBOX)
  76.         SetDialogBkColor();     
  77.  
  78.     // Create the main window
  79.     Cwm_MainWnd*  ms_pMainUserWnd;
  80.     ms_pMainUserWnd   = BLDMainCreateWnd(NULL);
  81.     m_pMainWnd        = ms_pMainUserWnd;
  82.  
  83.  
  84.     ::GetModuleFileName(AfxGetInstanceHandle(),ms_szHelpFilePath,sizeof(ms_szHelpFilePath));
  85.     len=lstrlen(ms_szHelpFilePath);
  86.     for (pStr=&ms_szHelpFilePath[len-1];pStr>ms_szHelpFilePath;--pStr)
  87.         {
  88.         if (*pStr=='\\')
  89.             {
  90.             pStr++;
  91.             lstrcpy(pStr,"DOCTEMP.HLP");
  92.             if (!::OpenFile(ms_szHelpFilePath,&of,OF_EXIST)!=-1)
  93.                 {
  94.                 lstrcpy(ms_szHelpFilePath,"DOCTEMP.HLP");
  95.                 }
  96.             break;
  97.             }         
  98.         }
  99.     m_pszHelpFilePath = ms_szHelpFilePath;
  100.  
  101.  
  102.     return CWinApp::InitInstance();
  103. }
  104.  
  105.  
  106.  
  107. int Cwm_BaseApplication::ExitInstance()
  108. {
  109.  
  110.     return CWinApp::ExitInstance();
  111. }
  112.  
  113.  
  114.  
  115. //No help support, return FALSE
  116. BOOL Cwm_BaseApplication::MenuHelp(DWORD dwData)
  117.     {
  118.     return FALSE;
  119.     }
  120.  
  121.  
  122.  
  123. // *************************************************************
  124. // Member Functions for Class: Cwm_MainBaseWnd
  125. // Base Class                : CMDIFrameWnd
  126. // *************************************************************
  127.  
  128.  
  129. CString Cwm_MainBaseWnd::ms_strWndClass; //Window Class Name
  130.  
  131.  
  132. IMPLEMENT_DYNCREATE(Cwm_MainBaseWnd, CMDIFrameWnd)
  133.  
  134. BEGIN_MESSAGE_MAP(Cwm_MainBaseWnd, CMDIFrameWnd)
  135.  
  136.     ON_REGISTERED_MESSAGE(wPrivateMessage,SimHandlePrivateMessage)
  137.  
  138. END_MESSAGE_MAP()
  139.  
  140.  
  141.  
  142. Cwm_MainBaseWnd::Cwm_MainBaseWnd()
  143.     : CMDIFrameWnd()
  144. {
  145.  
  146.     ms_pToolbarTop= ms_pToolbarBottom=ms_pToolbarLeft=ms_pToolbarRight=NULL;
  147.     ms_pWndClient = NULL;
  148.  
  149.  
  150.     if (ms_strWndClass.IsEmpty())
  151.        SimRegisterClass();
  152.  
  153. }
  154.  
  155.  
  156.  
  157. Cwm_MainBaseWnd::~Cwm_MainBaseWnd()
  158. {
  159. }
  160.  
  161.  
  162.  
  163. BOOL Cwm_MainBaseWnd::SimRegisterClass()
  164. {
  165.     WNDCLASS    WndClass;
  166.  
  167.     WndClass.lpszClassName = "BLD_Main";
  168.     WndClass.style         = CS_DBLCLKS;
  169.     WndClass.cbClsExtra    = 0;
  170.     WndClass.cbWndExtra    = 0;
  171.     WndClass.hInstance     = AfxGetInstanceHandle();
  172.     WndClass.hIcon         = LoadIcon(AfxGetResourceHandle(),"MDIEDIT");
  173.     WndClass.hCursor       = LoadCursor(NULL,IDC_ARROW);
  174.     WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  175.     WndClass.lpszMenuName  = "SIMPLE";
  176.  
  177.     if (!ms_strWndClass.IsEmpty())
  178.         return TRUE;                      // Already registered
  179.  
  180.     ms_strWndClass = AfxRegisterWndClass(WndClass.style,
  181.        WndClass.hCursor, WndClass.hbrBackground, WndClass.hIcon);
  182.  
  183.     if (ms_strWndClass.IsEmpty())
  184.         return FALSE;
  185.     else
  186.         return TRUE;
  187. }
  188.  
  189.  
  190.  
  191. BOOL Cwm_MainBaseWnd::SimInitWindow(CWnd *pAParent)
  192. {
  193.     CREATESTRUCT        sCr;
  194.  
  195.     if (ms_strWndClass.IsEmpty())
  196.        return FALSE;
  197.  
  198.     sCr.lpCreateParams  = NULL;
  199.     sCr.hInstance       = AfxGetInstanceHandle();
  200.     sCr.dwExStyle       = 0;
  201.     sCr.lpszClass       = ms_strWndClass;
  202.     sCr.lpszName        = "MDI Framework 1";
  203.     sCr.style           = WS_CAPTION | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_OVERLAPPED;
  204.     sCr.hwndParent      = pAParent ? pAParent->GetSafeHwnd() : (HWND)NULL;
  205.     sCr.x               = CW_USEDEFAULT;
  206.     sCr.y               = 0;
  207.     sCr.cx              = CW_USEDEFAULT;
  208.     sCr.cy              = 0;
  209.     sCr.hMenu           = NULL;
  210.     ms_hSubMenu             = 0;
  211.     ms_hSetWindowMenuPopup  = 0;
  212.  
  213.  
  214.     BOOL                bRet;
  215.  
  216.     if (sCr.cx==CW_USEDEFAULT)
  217.         {
  218.         bRet            = Create(ms_strWndClass,sCr.lpszName,sCr.style,
  219.                                  rectDefault,pAParent,
  220.                                  MAKEINTRESOURCE(IDR_SIMPLE),sCr.dwExStyle);
  221.         }
  222.     else
  223.         {
  224.         RECT            r;
  225.  
  226.         r.left          = sCr.x;
  227.         r.top           = sCr.y;
  228.         r.right         = sCr.cx+sCr.x;
  229.         r.bottom        = sCr.cy+sCr.y;
  230.  
  231.         bRet            = Create(ms_strWndClass,sCr.lpszName,sCr.style,
  232.                                  r,pAParent,MAKEINTRESOURCE(IDR_SIMPLE),
  233.                                  sCr.dwExStyle);
  234.         }
  235.  
  236.     if (!bRet)
  237.         {
  238.         BLDDisplayMessage(::GetActiveWindow(),BLD_CannotCreateWindow,"Main",
  239.                           MB_OK | MB_ICONASTERISK);
  240.         return FALSE;
  241.         }
  242.  
  243.     BLDLoadAccelerators(this,IDR_SIMPLE);
  244.  
  245.  
  246.     // To initialize bitmaps in menus and MDI window menu
  247.     BLDLoadMenu(this,IDR_SIMPLE,&ms_hSubMenu,FALSE);
  248.     ShowWindow(TheApp.m_nCmdShow);
  249.     UpdateWindow();
  250.  
  251.     return TRUE;
  252. }
  253.  
  254.  
  255. // PreCreateWindow - overridden for window to get correct properties
  256. BOOL Cwm_MainBaseWnd::PreCreateWindow(CREATESTRUCT& sCr)
  257. {
  258.     if (!sCr.lpszClass&&bPreCreateCheck)
  259.         {
  260.         HMENU           hSubMenu;
  261.  
  262.         sCr.dwExStyle   = 0;
  263.         sCr.lpszClass   = ms_strWndClass;
  264.         sCr.lpszName    = "MDI Framework 1";
  265.         sCr.style       = WS_CAPTION | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_OVERLAPPED;
  266.  
  267.         ms_hSubMenu             = 0;
  268.         ms_hSetWindowMenuPopup  = 0;
  269.  
  270.         if (sCr.hMenu&&::IsMenu(sCr.hMenu))
  271.             ::DestroyMenu(sCr.hMenu);
  272.         sCr.hMenu       = BLDLoadMenu(NULL,IDR_SIMPLE,&hSubMenu,TRUE);
  273.         }
  274.     return CMDIFrameWnd::PreCreateWindow(sCr);
  275. }
  276.  
  277.  
  278.  
  279. void Cwm_MainBaseWnd::Cwm_SetWindowMenuPopup(HMENU hMenu)
  280. {
  281.     ms_hSetWindowMenuPopup=hMenu;
  282. }
  283.  
  284.  
  285.  
  286. //Change MFC default setting of WindowMenuPopup if Cwm_SetWindowMenuPopup
  287. //is called by any MDI Child windows
  288. HMENU Cwm_MainBaseWnd::GetWindowMenuPopup(HMENU hMenuBar)
  289. {
  290.     if(ms_hSetWindowMenuPopup)
  291.         {
  292.         HMENU hMenuReturn;
  293.         hMenuReturn=ms_hSetWindowMenuPopup;
  294.         ms_hSetWindowMenuPopup=NULL;
  295.         return hMenuReturn;
  296.         }
  297.     if(m_hMenuDefault == hMenuBar)
  298.         return  ms_hSubMenu;
  299.     return CMDIFrameWnd::GetWindowMenuPopup(hMenuBar);
  300. }
  301.  
  302.  
  303.  
  304. BOOL Cwm_MainBaseWnd::OnCreateClient(LPCREATESTRUCT lpcs,
  305.         CCreateContext* pContext)
  306. {
  307.     BOOL bRetval;
  308.     int ChildMenuPos;
  309.     CMenu* pMenu = NULL;
  310.     HMENU hMenu;
  311.  
  312.     ChildMenuPos = -2;
  313.  
  314.     hMenu = BLDGetMDISubMenu(GetMenu()->GetSafeHmenu(),ChildMenuPos);
  315.     if(hMenu)
  316.         {
  317.         CMenu* pCMenu = CMenu::FromHandle(hMenu);
  318.         bRetval = CreateClient(lpcs, pMenu);
  319.         }
  320.     else
  321.         bRetval = CreateClient(lpcs, NULL);
  322.     DWORD dwStyle=::GetWindowLong(m_hWndMDIClient,GWL_STYLE);
  323.  
  324.     if(dwStyle & MDIS_ALLCHILDSTYLES)
  325.         {
  326.         dwStyle -=MDIS_ALLCHILDSTYLES;
  327.         ::SetWindowLong(m_hWndMDIClient,GWL_STYLE,dwStyle);
  328.         }
  329.  
  330.  
  331.     m_hMenuDefault      = GetMenu()->GetSafeHmenu();
  332.  
  333.     return bRetval;
  334. }
  335.  
  336.  
  337.  
  338. LRESULT Cwm_MainBaseWnd::SimHandlePrivateMessage(WPARAM wParam,LPARAM lParam)
  339. {
  340.     LPBLDSetChildDialog lpSetChildDialog;
  341.     switch(wParam)
  342.         {
  343.     case SIM_GETCHILDDIALOG:
  344.         switch(LOWORD(lParam))
  345.             {
  346.         case 0: //Client area controls
  347.             return (LRESULT)(LPSTR)(CSimClientDlg*)ms_pWndClient;
  348.         case CBRS_RIGHT:
  349.             return (LRESULT)(LPSTR)(CSimToolbar*)ms_pToolbarRight;
  350.         case CBRS_LEFT:
  351.             return (LRESULT)(LPSTR)(CSimToolbar*)ms_pToolbarLeft;
  352.         case CBRS_BOTTOM:
  353.             return (LRESULT)(LPSTR)(CSimToolbar*)ms_pToolbarBottom;
  354.         case CBRS_TOP:
  355.             return (LRESULT)(LPSTR)(CSimToolbar*)ms_pToolbarTop;
  356.             }
  357.         break;
  358.     case SIM_SETCHILDDIALOG:
  359.         lpSetChildDialog = (LPBLDSetChildDialog)lParam;
  360.         switch(lpSetChildDialog->nStyle)
  361.             {
  362.         case 0: //Client area controls
  363.             ms_pWndClient     = (CSimClientDlg*)lpSetChildDialog->pWnd;
  364.             break;
  365.         case CBRS_RIGHT:
  366.             ms_pToolbarRight  = (CSimToolbar*)lpSetChildDialog->pWnd;
  367.             break;
  368.         case CBRS_LEFT:
  369.             ms_pToolbarLeft   = (CSimToolbar*)lpSetChildDialog->pWnd;
  370.             break;
  371.         case CBRS_BOTTOM:
  372.             ms_pToolbarBottom = (CSimToolbar*)lpSetChildDialog->pWnd;
  373.             break;
  374.         case CBRS_TOP:
  375.             ms_pToolbarTop    = (CSimToolbar*)lpSetChildDialog->pWnd;
  376.             break;
  377.             }
  378.         break;
  379.     case SIM_RELOADACCELERATORS:
  380.         BLDLoadAccelerators(this,IDR_SIMPLE);
  381.         break;
  382.     case SIM_LOADACCELTABLE:
  383.         if(m_hAccelTable)
  384.             m_hAccelTable=0;
  385.         if(lParam)
  386.             LoadAccelTable(MAKEINTRESOURCE((int)lParam));
  387.         break;
  388.         }
  389.     return 0;
  390. }
  391.  
  392.  
  393. // *************************************************************
  394. //        FUNCTION FOR SWITCHING MENU SET
  395. // *************************************************************
  396.  
  397. BOOL BLDSwitchMenu(CWnd *pWnd,char *pTemplateName)
  398.     {
  399.     HMENU       hMenu1,hMenu,hSubMenu;
  400.     DWORD       style;
  401.  
  402.     hMenu       = 0;
  403.     hSubMenu    = 0;
  404.     
  405.     style = pWnd->GetStyle();
  406.     if((style & WS_CHILD) == WS_CHILD)     //  Called from control in main window? 
  407.         {
  408.         pWnd=pWnd->GetParent();
  409.         if (!pWnd)
  410.             return FALSE;
  411.         style = pWnd->GetStyle();
  412.         if((style & WS_CHILD) == WS_CHILD) //  No menu in a WS_CHILD window.
  413.             return FALSE;
  414.         }
  415.     if((style & WS_CAPTION) != WS_CAPTION) //  No menu if no caption.
  416.         return FALSE;
  417.     
  418.     hMenu1 = pWnd->GetMenu()->GetSafeHmenu();
  419.  
  420.     if (lstrcmpi(pTemplateName,"SIMPLE")==0)
  421.         hMenu = BLDLoadMenu(pWnd,IDR_SIMPLE,&hSubMenu,TRUE);
  422.  
  423.     if (!hMenu)
  424.         hMenu = LoadMenu(AfxGetResourceHandle(),pTemplateName);
  425.     if (!hMenu)
  426.         {
  427.         BLDDisplayMessage(pWnd->GetSafeHwnd(),BLD_CannotLoadMenu,pTemplateName,
  428.                           MB_OK | MB_ICONASTERISK);
  429.         return FALSE;
  430.         }
  431.     
  432.     if(pWnd->GetSafeHwnd() != TheApp.m_pMainWnd->GetSafeHwnd())
  433.         {
  434.         if (!pWnd->SetMenu(CMenu::FromHandle(hMenu)))
  435.             return FALSE;
  436.         if (hMenu1)
  437.             DestroyMenu(hMenu1);
  438.         }
  439.     else
  440.         {
  441.         Cwm_MainWnd *pCwm_MainWnd = (Cwm_MainWnd *)TheApp.m_pMainWnd;
  442.         pCwm_MainWnd->MDISetMenu(CMenu::FromHandle(hMenu),CMenu::FromHandle(hSubMenu));
  443.  
  444.         if(pCwm_MainWnd->m_hMenuDefault)
  445.             ::DestroyMenu(pCwm_MainWnd->m_hMenuDefault);
  446.         pCwm_MainWnd->m_hMenuDefault=hMenu;
  447.         pCwm_MainWnd->ms_hSubMenu   =hSubMenu;
  448.         }
  449.     
  450.     pWnd->DrawMenuBar();
  451.     return TRUE;
  452.     }
  453.  
  454.  
  455. //  Code to load menu and add bitmaps
  456. HMENU BLDLoadMenu(CWnd *pWnd,int iResource,HMENU *phSubMenu,BOOL bLoad)
  457.     {
  458.     HMENU       hMenu;
  459.     int         iMenuPos;
  460.  
  461.     *phSubMenu  = 0;
  462.     iMenuPos    = -2;
  463.     if (bLoad)
  464.         hMenu   = LoadMenu(AfxGetResourceHandle(),MAKEINTRESOURCE(iResource));
  465.     else
  466.         {
  467.         if (!pWnd)
  468.             return FALSE;
  469.         hMenu   = pWnd->GetMenu()->GetSafeHmenu();
  470.         }
  471.  
  472.     if(!hMenu)
  473.         return FALSE;
  474.  
  475.  
  476.     if (pWnd)
  477.         BLDLoadAccelerators(pWnd,iResource);
  478.  
  479.     *phSubMenu=BLDGetMDISubMenu(hMenu,iMenuPos);
  480.     return hMenu;
  481.     }
  482.  
  483.  
  484. //  Code to load accelerators
  485. BOOL BLDLoadAccelerators(CWnd *pWnd,int iResource)
  486.     {
  487.  
  488.     switch (iResource)
  489.         {
  490.     case IDR_SIMPLE:
  491.         pWnd->SendMessage(wPrivateMessage,SIM_LOADACCELTABLE,(LONG)iResource);
  492.         break;
  493.         }
  494.     return TRUE;
  495.     }
  496.  
  497.  
  498. HMENU BLDGetMDISubMenu(HMENU hMenu,int iMenuPos)
  499.     {
  500.     HMENU       hSubMenu;
  501.     int         i,iCount;
  502.  
  503.     if(!hMenu)
  504.         return 0;
  505.  
  506.     hSubMenu    = 0;
  507.  
  508.     switch(iMenuPos)
  509.         {
  510.     case -1:  //No MDI Window Menu
  511.         return 0;
  512.         break;
  513.     case -2:  //Default MDI Window Menu
  514.         break;
  515.     default:  //Specific MDI Window Menu
  516.         hSubMenu=GetSubMenu(hMenu,iMenuPos);
  517.         if(hSubMenu)
  518.             return hSubMenu;
  519.         break;
  520.         }
  521.  
  522.     //Find default MDI Window Menu
  523.     if(GetMenuItemCount(hMenu) > 0)
  524.         {
  525.         iCount   = GetMenuItemCount(hMenu);
  526.         if (iCount>=2)
  527.             hSubMenu = GetSubMenu(hMenu,iCount-2);
  528.         for(i=iCount-1; i>=0 && !hSubMenu; i--)
  529.             hSubMenu=GetSubMenu(hMenu,i);
  530.         }
  531.     return hSubMenu;
  532.     }
  533.